/*    */ package org.appfuse.util;
/*    */ 
/*    */ import java.util.Enumeration;
/*    */ import java.util.HashMap;
/*    */ import java.util.LinkedHashMap;
/*    */ import java.util.List;
/*    */ import java.util.Map;
/*    */ import java.util.Properties;
/*    */ import java.util.ResourceBundle;
/*    */ import org.apache.commons.beanutils.BeanUtils;
/*    */ import org.apache.commons.logging.Log;
/*    */ import org.apache.commons.logging.LogFactory;
/*    */ import org.appfuse.model.LabelValue;
/*    */ 
/*    */ public final class ConvertUtil
/*    */ {
/* 23 */   private static final Log log = LogFactory.getLog(ConvertUtil.class);
/*    */ 
/*    */   public static Map<String, String> convertBundleToMap(ResourceBundle rb)
/*    */   {
/* 38 */     Map map = new HashMap();
/*    */ 
/* 40 */     Enumeration keys = rb.getKeys();
/* 41 */     while (keys.hasMoreElements()) {
/* 42 */       String key = (String)keys.nextElement();
/* 43 */       map.put(key, rb.getString(key));
/*    */     }
/*    */ 
/* 46 */     return map;
/*    */   }
/*    */ 
/*    */   public static Map<String, String> convertListToMap(List<LabelValue> list)
/*    */   {
/* 56 */     Map map = new LinkedHashMap();
/*    */ 
/* 58 */     for (LabelValue option : list) {
/* 59 */       map.put(option.getLabel(), option.getValue());
/*    */     }
/*    */ 
/* 62 */     return map;
/*    */   }
/*    */ 
/*    */   public static Properties convertBundleToProperties(ResourceBundle rb)
/*    */   {
/* 72 */     Properties props = new Properties();
/*    */ 
/* 74 */     for (Enumeration keys = rb.getKeys(); keys.hasMoreElements(); ) {
/* 75 */       String key = (String)keys.nextElement();
/* 76 */       props.put(key, rb.getString(key));
/*    */     }
/*    */ 
/* 79 */     return props;
/*    */   }
/*    */ 
/*    */   public static Object populateObject(Object obj, ResourceBundle rb)
/*    */   {
/*    */     try
/*    */     {
/* 92 */       Map map = convertBundleToMap(rb);
/* 93 */       BeanUtils.copyProperties(obj, map);
/*    */     } catch (Exception e) {
/* 95 */       e.printStackTrace();
/* 96 */       log.error("Exception occurred populating object: " + e.getMessage());
/*    */     }
/*    */ 
/* 99 */     return obj;
/*    */   }
/*    */ }

